﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manage_ShowBidStatus : System.Web.UI.Page
{
    string format1 = "待报价企业总数：<span style='color:Red'>{2}</span>个，已报价企业总数：<span style='color:Red'>{3}</span>个。<br />待报价产品数：<span style='color:Red'>{0}</span>个，已报价产品数：<span style='color:Red'>{1}</span>个。";
    string format2 = "待解密企业总数：<span style='color:Red'>{2}</span>个，已解密企业总数：<span style='color:Red'>{3}</span>个。<br />待解密产品数：<span style='color:Red'>{0}</span>个，已解密产品数：<span style='color:Red'>{1}</span>个。";
    string isdec;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (CurrentAccount.Account == null)
        {
            lkbExport.Visible = false;
            Response.Redirect("../UserLogin.aspx");
            return;
        }
        else
        {
            string userType = "";
            userType = CurrentAccount.Account.AccountType.Value.ToString();
            if (userType != "0" && userType != "1")
            {
                lkbExport.Visible = false;
                Response.Redirect("../UserLogin.aspx");
                return;
            }
            else
            {
                isdec = Request["isdec"] ?? "0";
                if (isdec == "0")
                {
                    int totalcount = (int)HZ.Data.DbHelperFactory.Create().ExecuteScalar("SELECT COUNT(BidId) FROM dbo.TB_Project_Bid");
                    int bidgoodscount = (int)HZ.Data.DbHelperFactory.Create().ExecuteScalar("SELECT COUNT(BidId) FROM dbo.TB_Project_Bid WHERE isnull(EncryptPrice,'')!='' and CompanyId in (SELECT CompanyId FROM dbo.TB_Company_Project_Switch WHERE ConfirmStatus =1)");
                    int totalcompany = (int)HZ.Data.DbHelperFactory.Create().ExecuteScalar("SELECT COUNT(DISTINCT CompanyId) FROM dbo.TB_Project_Bid");
                    int bidcompany = (int)HZ.Data.DbHelperFactory.Create().ExecuteScalar("SELECT COUNT(DISTINCT CompanyId) FROM dbo.TB_Project_Bid WHERE isnull(EncryptPrice,'')!=''  and CompanyId in (SELECT CompanyId FROM dbo.TB_Company_Project_Switch WHERE ConfirmStatus =1)");
                    // lblInfo.Text = string.Format(format1, totalcount, bidgoodscount, totalcompany, bidcompany);
                    //第三条数据为，未报价企业数 2016-6-15
                    //int totalbidCompany = BLL_Factory.IBLL_Common.GetAllCompnayCount();
                    lblInfo.Text = string.Format(format1, totalcount, bidgoodscount, totalcompany, bidcompany);
                }
                else
                {
                    // DecPrice
                    int totalcount = (int)HZ.Data.DbHelperFactory.Create().ExecuteScalar("SELECT COUNT(BidId) FROM dbo.TB_Project_Bid WHERE isnull(EncryptPrice,'')!=''  and CompanyId in (SELECT CompanyId FROM dbo.TB_Company_Project_Switch WHERE ConfirmStatus =1)");
                    int bidgoodscount = (int)HZ.Data.DbHelperFactory.Create().ExecuteScalar("SELECT COUNT(BidId) FROM dbo.TB_Project_Bid WHERE DecPrice Is not null and CompanyId in (SELECT CompanyId FROM dbo.TB_Company_Project_Switch WHERE DecStatus =1)");
                    int totalcompany = (int)HZ.Data.DbHelperFactory.Create().ExecuteScalar("SELECT COUNT(DISTINCT CompanyId) FROM dbo.TB_Project_Bid WHERE isnull(EncryptPrice,'')!='' and CompanyId in (SELECT CompanyId FROM dbo.TB_Company_Project_Switch WHERE ConfirmStatus =1)");
                    int bidcompany = (int)HZ.Data.DbHelperFactory.Create().ExecuteScalar("SELECT COUNT(DISTINCT CompanyId) FROM dbo.TB_Project_Bid WHERE DecPrice IS NOT NULL  and CompanyId in (SELECT CompanyId FROM dbo.TB_Company_Project_Switch WHERE DecStatus =1)");
                    //string format2 = "待解密企业总数：<span style='color:Red'>{2}</span>个，已解密企业总数：<span style='color:Red'>{3}</span>个。<br />待解密产品数：<span style='color:Red'>{0}</span>个，已解密产品数：<span style='color:Red'>{1}</span>个。";
                    lblInfo.Text = string.Format(format2, totalcount, bidgoodscount, totalcompany, bidcompany);
                }
            }
        }
    }
    protected void lkbExport_Click(object sender, EventArgs e)
    {
        if (isdec == "0")
        {
            var dt = HZ.Data.DbHelperFactory.Create().ExecuteTable("SELECT CompanyId AS 企业编码, CompanyName AS 企业名称, UserCode AS 企业注册号,telephone as 联系方式,LicenseeMan 被授权人 FROM TB_Company WHERE CompanyID IN (SELECT CompanyId FROM dbo.TB_Company_Project_Switch WHERE ConfirmStatus =0)");
            HZ.Web.WebUtil.ExportToExcel(dt, "nobidcompanylist.xls");
        }
        else
        {
            var dt = HZ.Data.DbHelperFactory.Create().ExecuteTable("SELECT CompanyId AS 企业编码, CompanyName AS 企业名称, UserCode AS 企业注册号,telephone as 联系方式,LicenseeMan 被授权人 FROM TB_Company WHERE CompanyID  IN (SELECT CompanyId FROM  dbo.TB_Company_Project_Switch WHERE ConfirmStatus =1 and DecStatus = 0)");
            HZ.Web.WebUtil.ExportToExcel(dt, "nodeccompanylist.xls");
        }
    }
}
